#include "ros/ros.h"
#include <opencv2/opencv.hpp>
#include <vector>
#include <iostream>
#include "dip_ex1_node.h"
using namespace cv;
using namespace std;   

int main(){
	MyHist histogram;
	MyGrayHist gray_histogram;
    VideoCapture cap = cv::VideoCapture(0);
    if(!cap.isOpened()){
        cout<<"can't open camera"<<endl;
        return 0;
    }
    cv::Mat frame;
    while (waitKey(2)!=27){
        cap.read(frame);
        if(frame.empty()){
            cout<<"empty frame"<<endl;
            return 0;
        }
        Mat normal_img = frame.clone();
	Mat hist_img(256,256,CV_8UC3,Scalar(0,0,0));
	Mat hist_img_after(256,256,CV_8UC3,Scalar(0,0,0));

	//for gray 
	Mat gray;
	cvtColor(frame,gray,CV_BGR2GRAY);
        //histogram.clear();
        histogram.calc(frame);
	histogram.visualize(hist_img);
        int ret = histogram.normalizeHist(normal_img);
	histogram.calc(normal_img);
	histogram.visualize(hist_img_after);
	
	//for gray
	Mat hist_gray_img(256,256,CV_8UC1,Scalar(0));
	Mat hist_gray_img_after(256,256,CV_8UC1,Scalar(0));
	gray_histogram.calc(gray);
	Mat normal_gray(gray);
	gray_histogram.normalizeHist(normal_gray);
	gray_histogram.visualize(hist_gray_img);
	gray_histogram.calc(normal_gray);
	gray_histogram.visualize(hist_gray_img_after);
        imshow("src",frame);
        imshow("normalize",normal_img);
	imshow("histogram",hist_img);
	imshow("histogram_after",hist_img_after);

	imshow("gray",gray);
	imshow("gray_normalize",normal_gray);
	imshow("hist gray",hist_gray_img);
	imshow("hist gray after",hist_gray_img_after);
        
        
    }
    return 0;
}
